#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>

class StateNode {
public:
    int state_id;
    bool is_final;
    std::unordered_map<char, std::set<int>> transitions;
    std::set<int> epsilon_closure;  // ε-闭包
    StateNode() : state_id(-1), is_final(false) {} // 添加无参数构造函数

    StateNode(int id) : state_id(id), is_final(false) {}
};

class Graph {
public:
    std::unordered_map<int, StateNode> nodes;

    void calculateEpsilonClosure(int start_state) {
        std::set<int> visited;
        dfsEpsilonClosure(start_state, start_state, visited);
    }

private:
    void dfsEpsilonClosure(int start_state, int current_state, std::set<int>& visited) {
        visited.insert(current_state);
        nodes[start_state].epsilon_closure.insert(current_state);

        for (int next_state : nodes[current_state].transitions['ε']) {
            if (visited.find(next_state) == visited.end()) {
                dfsEpsilonClosure(start_state, next_state, visited);
            }
        }
    }
};

int main() {
    Graph graph;
    // 构建一个简单的有向图
    StateNode node0(0);
    StateNode node1(1);
    StateNode node2(2);

    node0.transitions['ε'].insert(1);
    node1.transitions['a'].insert(2);
    node2.is_final = true;

    graph.nodes[0] = node0;
    graph.nodes[1] = node1;
    graph.nodes[2] = node2;

    // 对节点0求ε-闭包
    graph.calculateEpsilonClosure(0);

    // 输出节点0的ε-闭包
    std::cout << "ε-Closure for state 0: ";
    for (int state : graph.nodes[0].epsilon_closure) {
        std::cout << state << " ";
    }

    return 0;
}
